package com.ruoyi.cmemetal.controller;

import java.util.HashMap;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.StringUtils;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.cmemetal.domain.ZxOrderUrl;
import com.ruoyi.cmemetal.service.IZxOrderUrlService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * zxorderurlController
 *
 * @author zhangxu
 * @date 2021-12-28
 */
@RestController
@RequestMapping("/cmemetal/zxorderurl")
public class ZxOrderUrlController extends BaseController
{
    @Autowired
    private IZxOrderUrlService zxOrderUrlService;

    /**
     * 查询zxorderurl列表
     */
//    @PreAuthorize("@ss.hasPermi('cmemetal:zxorderurl:list')")
    @GetMapping("/list")
    public TableDataInfo list( ZxOrderUrl zxOrderUrl)
    {

        startPage();
        List<ZxOrderUrl> list = zxOrderUrlService.selectZxOrderUrlList(zxOrderUrl);
        return getDataTable(list);
    }

    /**
     * 导出zxorderurl列表
     */
    @PreAuthorize("@ss.hasPermi('cmemetal:zxorderurl:export')")
    @Log(title = "zxorderurl", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, ZxOrderUrl zxOrderUrl)
    {
        List<ZxOrderUrl> list = zxOrderUrlService.selectZxOrderUrlList(zxOrderUrl);
        ExcelUtil<ZxOrderUrl> util = new ExcelUtil<ZxOrderUrl>(ZxOrderUrl.class);
        util.exportExcel(response, list, "zxorderurl数据");
    }

    /**
     * 获取zxorderurl详细信息
     */
    @PreAuthorize("@ss.hasPermi('cmemetal:zxorderurl:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id)
    {
        return AjaxResult.success(zxOrderUrlService.selectZxOrderUrlById(id));
    }

    /**
     * 新增zxorderurl
     */
//    @PreAuthorize("@ss.hasPermi('cmemetal:zxorderurl:add')")
    @Log(title = "zxorderurl", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody ZxOrderUrl zxOrderUrl)
    {
        return toAjax(zxOrderUrlService.insertZxOrderUrl(zxOrderUrl));
    }

    /**
     * 修改zxorderurl
     */
    @PreAuthorize("@ss.hasPermi('cmemetal:zxorderurl:edit')")
    @Log(title = "zxorderurl", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody ZxOrderUrl zxOrderUrl)
    {
        return toAjax(zxOrderUrlService.updateZxOrderUrl(zxOrderUrl));
    }

    /**
     * 删除zxorderurl
     */
    @PreAuthorize("@ss.hasPermi('cmemetal:zxorderurl:remove')")
    @Log(title = "zxorderurl", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids)
    {
        return toAjax(zxOrderUrlService.deleteZxOrderUrlByIds(ids));
    }


    //获取下载文件信息
    @GetMapping("/getFileInformation")
    public AjaxResult getFileInformation(ZxOrderUrl zxOrderUrl){
        AjaxResult ajaxResult = new AjaxResult();
        List<ZxOrderUrl> list = zxOrderUrlService.selectZxOrderUrlList(zxOrderUrl);
        if(list.size() != 0){
            ZxOrderUrl zxOrderUrl1 = list.get(0);
            if(StringUtils.isNotEmpty(zxOrderUrl1.getOrderUpload())){
                String orderfilename = "." +  StringUtils.substringAfterLast(zxOrderUrl1.getOrderUpload(), ".");
                ajaxResult.put("orderfilename",orderfilename);
                ajaxResult.put("orderurl",zxOrderUrl1.getOrderUpload());
            }

            if(StringUtils.isNotEmpty(zxOrderUrl1.getPerprocessUpload())){
                String predatafilename ="." +  StringUtils.substringAfterLast(zxOrderUrl1.getPerprocessUpload(), ".");
                ajaxResult.put("predatafilename",predatafilename);
                ajaxResult.put("predataurl",zxOrderUrl1.getPerprocessUpload());
            }

        }




        return ajaxResult;

    }
}
